const express = require('express');
const router = express.Router();
const {
  createWarehouse,
  getWarehouses,
  getWarehouseById,
  updateWarehouse,
  deleteWarehouse,
  batchDeleteWarehouses,
  getWarehouseFruits,
  addFruitToWarehouse,
  updateWarehouseFruit,
  removeFruitFromWarehouse
} = require('../controllers/warehouseController');
const { authenticate } = require('../middleware/auth');

// 所有仓库路由都需要认证
router.use(authenticate);

// 获取仓库列表
router.get('/', getWarehouses);

// 获取单个仓库详情
router.get('/:id', getWarehouseById);

// 创建仓库
router.post('/', createWarehouse);

// 批量删除仓库
router.post('/batch-delete', batchDeleteWarehouses);

// 更新仓库
router.put('/:id', updateWarehouse);

// 删除仓库
router.delete('/:id', deleteWarehouse);

// 仓库水果管理路由
// 获取仓库中的水果列表
router.get('/:id/fruits', getWarehouseFruits);

// 添加水果到仓库
router.post('/:id/fruits', addFruitToWarehouse);

// 更新仓库中水果的数量
router.put('/:id/fruits/:fruitWarehouseId', updateWarehouseFruit);

// 从仓库移除水果
router.delete('/:id/fruits/:fruitWarehouseId', removeFruitFromWarehouse);

module.exports = router;

